package com.idlefish.flutterboost;


import java.util.LinkedList;
import java.util.List;

public class FlutterPayManager {

    /**
     * 支付成功
     */
    public static final String PAY_STATUS_SUCCESS = "success";
    /**
     * 支付失败
     */
    public static final String PAY_STATUS_FAIL = "fail";
    /**
     * 支付确认中
     */
    public static final String PAY_STATUS_CONFIRM = "confirm";

    private static FlutterPayManager instance;
    private String flutterForm;

    public String getFlutterForm() {
        return flutterForm;
    }

    public void setFlutterForm(String flutterForm) {
        this.flutterForm = flutterForm;
    }

    public static FlutterPayManager getInstance() {
        synchronized (FlutterPayManager.class) {
            if (instance == null) {
                instance = new FlutterPayManager();
            }
        }
        return instance;
    }

    private List<CallBack<String>> list = new LinkedList<>();


    public void register(CallBack<String> callBack) {
        if (list != null && !list.contains(callBack)) {
            list.add(callBack);
        }
    }

    public void unRegister(CallBack<String> callBack) {
        if (list != null) {
            list.remove(callBack);
        }
    }

    public void notifyObservers(String status) {
        if (list != null) {
            for (CallBack<String> callBack : list) {
                if (callBack != null) {
                    callBack.onCall(status);
                }
            }
        }
    }
}
